﻿#include "Settings.h"

namespace AutoPatcher
{

InIReader *const Settings::Reader = new InIReader(R"(.\Mir2Config.ini)");
std::string Settings::Host = R"()";
std::string Settings::PatchFileName = R"(PList.gz)";
bool Settings::NeedLogin = false;
std::string Settings::Login = "";
std::string Settings::Password = "";
bool Settings::AllowCleanUp = true;
std::string Settings::Client;
bool Settings::AutoStart = false;

    void Settings::Load()
    {

        Host = Reader->ReadString("AutoPatcher", "Host", Host);
        PatchFileName = Reader->ReadString("AutoPatcher", "PatchFile", PatchFileName);

        NeedLogin = Reader->ReadBoolean("AutoPatcher", "NeedLogin", NeedLogin);
        Login = Reader->ReadString("AutoPatcher", "Login", Login);
        Password = Reader->ReadString("AutoPatcher", "Password", Password);

        AllowCleanUp = Reader->ReadBoolean("AutoPatcher", "AllowCleanUp", AllowCleanUp);
        AutoStart = Reader->ReadBoolean("AutoPatcher", "AutoStart", AutoStart);

        Client = Application::StartupPath + "\\";
        if (!StringHelper::endsWith(Host, "/"))
        {
            Host += "/";
        }
        if (Host.StartsWith("www.", StringComparison::OrdinalIgnoreCase))
        {
            Host.insert(0, "http://");
        }
    }
}
